package com.yegs.jltqc.controller;

import com.yegs.jltqc.TO.RpInComePageQuery;
import com.yegs.jltqc.TO.RpproducePageQuery;
import com.yegs.jltqc.VO.RpInCome;
import com.yegs.jltqc.VO.RpProduce;
import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.service.RpInComeService;
import com.yegs.jltqc.service.RpProduceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rpInCome")
public class RpInComeController {

    @Autowired
    private RpInComeService rpInComeService;

    @PostMapping("/save")
    public Msg save(@RequestBody RpInCome rpInCome){
        try{
            RpInCome inCome = rpInComeService.save(rpInCome);
            return Msg.success("data",inCome);
        }catch (Exception e){
            e.printStackTrace();
            return Msg.error(e.getMessage());
        }
    }

    @GetMapping("/get")
    public Msg get(@RequestParam Long id){
        return Msg.success("data", rpInComeService.get(id));
    }
    @GetMapping("/del")
    public Msg del(@RequestParam Long id){
        rpInComeService.del(id);
        return Msg.success();
    }
    @GetMapping("/getLast")
    public Msg getLast(@RequestParam(required = false) Long id){
        return Msg.success("data",rpInComeService.getLast(id));
    }
    @GetMapping("/getNext")
    public Msg getNext(@RequestParam(required = false) Long id){
        return Msg.success("data",rpInComeService.getNext(id));
    }

    @PostMapping("/query")
    public Msg query(@RequestBody RpInComePageQuery query){
        return Msg.success("page",rpInComeService.query(query));
    }

    @GetMapping("/findRpIncomeByBarcode")
    public Msg findRpProduceByBarcode(@RequestParam String cbarcode){
        return Msg.success("data", rpInComeService.findRpProduceByBarcode(cbarcode));
    }


    @GetMapping("/findRpIncomeBySubBarcode")
    public Msg findRpIncomeBySubBarcode(@RequestParam String cbarcode){
        return Msg.success("data", rpInComeService.findRpIncomeBySubBarcode(cbarcode));
    }
}
